﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnlessComment.Model;

namespace Web4Comment.Service
{
    public class HotTopicService
    {
        private static UnlessComment.BLL.HotTopic hotTopic = new UnlessComment.BLL.HotTopic();
        private static UnlessComment.BLL.User user = new UnlessComment.BLL.User();
        private static UnlessComment.BLL.News news = new UnlessComment.BLL.News();

        public static int addHotTopic(string username, string url, int rank, string addtion)
        {
            int userID = UserService.getUserid(username);
            int newsID = NewsService.getNewsId(url);

            if (userID == 0)
                return 0;
            if (newsID == 0)
                newsID = NewsService.addNews(url, addtion);

            UnlessComment.Model.HotTopic hotTopicModel = new UnlessComment.Model.HotTopic();
            hotTopicModel.add_time = DateTime.Now;
            hotTopicModel.addtion = addtion;
            hotTopicModel.clicks = 0;
            hotTopicModel.news_id = newsID;
            hotTopicModel.rank = rank;
            hotTopicModel.user_id = userID;

            return hotTopic.Add(hotTopicModel);
        }

        public static int deleteHotTopic()
        {
            return 0;
        }

        public static int modefyHotTopic()
        {
            return 0;
        }

        public static List<UnlessComment.Model.HotTopicInfo> getHotTopics(DateTime time)
        {
            List<UnlessComment.Model.HotTopic> list = new List<UnlessComment.Model.HotTopic>();
            List<UnlessComment.Model.HotTopicInfo> listInfo = new List<UnlessComment.Model.HotTopicInfo>();
            string start = time.Year + "-" + time.Month + "-" + time.Day + " 00:00:00.000";
            string end = time.Year + "-" + time.Month + "-" + time.Day + " 23:59:59.999";
            list = hotTopic.GetModelList("add_time between '" + start + "' and '" + end + "'");

            for (int i = 0; i < list.Count; i++)
            {
                listInfo.Add(new HotTopicInfo(list[i], user.GetModel(list[i].user_id), news.GetModel(list[i].news_id)));
            }

            return listInfo;
        }
    }
}
